package demo.jdbc.example;

import demo.jdbc.example.dao.UsersDao;
import demo.jdbc.example.domain.User;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

@WebServlet(name = "ServletFindAllUsersTest", value = "/ServletFindAllUsersTest")
public class ServletFindAllUsersTest extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 创建一个名称为userDao对象
        UsersDao usersDao = new UsersDao();
        // 将UsersDao对象的findAll()方法执行后的结果放入list集合
        ArrayList<User> list = usersDao.findAll();
        PrintWriter out = response.getWriter();
        // 循环输出合集中的数据
        for (int i = 0; i < list.size(); i++){
            out.print("user" + (i + 1) + ":" + list.get(i).getUsername() + "邮箱：" + list.get(i).getEmail() + "生日：" +list.get(i).getBirthday());
            out.print("<br>");
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

    }
}
